15. Take Action!
Take Action!
Sending Commands to the Rover
In this project, as in the real world, the perception and decision making steps constitute the bulk of the problem. In this case, the action step is simple! You'll be provided with a function called send_control()
that you can use to command the rover and display images to the simulator screen. It looks like this:
def send_control(commands, image_string1, image_string2):
# Define commands to be sent to the rover
data={
'throttle': commands[0].__str__(),
'brake': commands[1].__str__(),
'steering_angle': commands[2].__str__(),
'inset_image1': image_string1,
'inset_image2': image_string2,
}
# Send commands via socketIO server
sio.emit(
"data",
data,
skip_sid=True)
This function takes in the argument commands
, which is a 3-tuple containing the throttle, brake and steering values you have stored in the Rover.throttle
, Rover.brake
and Rover.steer
attributes of your RoverState()
object.
The other arguments are called image_string1
and image_string2
and will contain your Rover.vision_image
and Rover.worldmap
images converted to base64 strings that will be rendered onscreen while you're navigating in autonomous mode.
The send_control()
function creates a dictionary called data
with all of these values then passes this dictionary to the sio.emit()
function to send commands and images to the rover. You don't need to worry about exactly how this gets accomplished, just that once you have updated Rover.throttle
, Rover.brake
and Rover.steer
, your commands
input to send_control()
will be updated and each time you update Rover.vision_image
and Rover.worldmap
the two display images will be updated. And that's all there is to the action step!